package com.huqingshan.LenMore.service.implement;

import com.github.pagehelper.PageHelper;
import com.huqingshan.LenMore.model.entity.Orders;
import com.huqingshan.LenMore.model.enums.ORDERSTATUS;
import com.huqingshan.LenMore.model.enums.PAYTYPE;
import com.huqingshan.LenMore.model.enums.SORTENUM;
import com.huqingshan.LenMore.repository.dao.OrdersMapper;
import com.huqingshan.LenMore.service.OrdersService;
import com.huqingshan.LenMore.utils.CustomException.NotFoundException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author 卫鹏
 * @Description 订单表  业务层接口
 * @createTime 2021年11月19日 16:17:00
 */
@Service
//开启事务
@Transactional
public class OrdersServiceImpl implements OrdersService {

    @Autowired
    private OrdersMapper ordersMapper;

    /**
     * 可接受参数为产品支付方式，排序方式，支付状态
     * @param page
     * @param size
     * @return
     */
    @Override
    public List<Orders> findAll(Integer page, Integer size, SORTENUM sortEnum, ORDERSTATUS orderstatus, PAYTYPE paytype){

        PageHelper.startPage(page, size);
        return ordersMapper.findAll();

    }

    @Override
    public Orders findById(String ordersId) {
        return ordersMapper
                .findByOrdersId(ordersId)
                .orElseThrow(()->new NotFoundException("查询不到该订单的信息"));
    }
}
